package com.ruoyi.web.controller.manage;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.manage.domain.UserOrder;
import com.ruoyi.manage.service.IAppPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

/**
 * @author wwy
 * @date 2021-02-27 14:59
 */
@RestController
@RequestMapping("/api")
public class AppPageController {
    @Autowired
    private IAppPageService iAppPageService;
    @Autowired
    private TokenService tokenService;

    /**
     * 根据type获取轮播图
     * @param type
     * @return
     */
    @GetMapping("/slideshow/{type}")
    public AjaxResult findSlideshow(@PathVariable("type") Long type){
        return iAppPageService.findSlideshowByType(type);
    }

    /**
     * 获取公司简介
     * @return
     */
    @GetMapping("/getCompanyProfile")
    public AjaxResult getCompanyProfile(){
        return iAppPageService.getCompanyProfile();
    }

    /**
     * 获取婚纱套系
     * @return
     */
    @GetMapping("/getWeddingDress")
    public AjaxResult getWeddingDress(){
        return iAppPageService.getWeddingDress();
    }

    /**
     * 获取团队信息
     * @return
     */
    @GetMapping("/getTeam")
    public AjaxResult getTeam(){
        return iAppPageService.getTeam();
    }

    /**
     * 获取金牌团队详细信息
     * @param id
     * @return
     */
    @GetMapping("/getTeamDetail/{id}")
    public AjaxResult getTeamDetail(@PathVariable("id") Long id){
        return iAppPageService.getTeamDetail(id);
    }

    /**
     * 获取作品管理
     * @return
     */
    @GetMapping("/getWorkShow")
    public AjaxResult getWorkShow(){
        return iAppPageService.getWorkShow();
    }

    /**
     * 获取作品管理详情
     * @return
     */
    @GetMapping("/getWorkShowDetail/{id}")
    public AjaxResult getWorkShowDetail(@PathVariable("id") Long id){
        return iAppPageService.getWorkShowDetail(id);
    }

    /**
     * 保存预约单
     * @param userOrder
     * @return
     */
    @PostMapping("/saveOrder")
    public AjaxResult saveOrder(@RequestBody UserOrder userOrder, HttpServletRequest request){
        LoginUser loginUser = tokenService.getLoginUser(request);
        SysUser user = loginUser.getUser();
        String userName = user.getUserName();
        return iAppPageService.saveOrder(userOrder, userName);
    }

    /**
     * 获取订单列表
     * @return
     */
    @GetMapping("/getOrder")
    public AjaxResult getOrder(HttpServletRequest request){
        LoginUser loginUser = tokenService.getLoginUser(request);
        SysUser user = loginUser.getUser();
        String userName = user.getUserName();
        return iAppPageService.getOrder(userName);
    }

    /**
     * 移除订单
     * @param id
     * @return
     */
    @GetMapping("/removeOrder/{id}")
    public AjaxResult removeOrder(@PathVariable("id") Long id){
        return iAppPageService.removeOrder(id);
    }

    /**
     * 获取热点咨询
     * @return
     */
    @GetMapping("/getHotMessage")
    public AjaxResult getHotMessage(){
        return iAppPageService.getHotMessage();
    }
}